﻿package  {
	import com.janisRadins.asDraw.CubicCurve;
	import com.janisRadins.asDraw.Curve;
	import com.janisRadins.asDraw.Path;
	import com.janisRadins.asDraw.SVGPathParser;
	import flash.display.GraphicsPath;
	import flash.display.Sprite;
	import flash.geom.Point;
	import mx.utils.ObjectUtil;
	/**
	 * ...
	 * @author Jānis Radiņš
	 */
	public class T5 extends Sprite {
		public static var instance:T5 = null;
		public var clip2:Sprite;
		public function T5() {
			instance = this;
			clip2 = addChild(new Sprite) as Sprite;
			
			var parser:SVGPathParser = new SVGPathParser();
			//var data:String = "M 96,115.36218 C 104,116.36218 257,102.36218 257,102.36218 C 257,102.36218 319,122.36218 389,85.362183 C 459,48.362183 622,48.362183 531,80.362183 C 440,112.36218 630,116.36218 630,116.36218";
			
			//One cubic curve
			//var data:String = "M100,200 C100,100 250,100 250,200";
			
			//var data:String = "M100,200 c0,-100 150,-100 150,0 c0,100 150,100 150,0 l150,150 v50,50 h-100 L50,50";
			//Double cubic curve
			//var data:String = "M100,200 c0,-100 150,-100 150,0 c0,100 150,100 150,0 q0,100 100, 200";
			//var data:String = "M100,250 c0,-100 150,-100 150,0 s150,100 150,0 S150, 200 150,50";
			//var data:String = "M100,250 c0,-100 150,-100 150,0 q50,50 60,70 t50,0 50,0 50,0 50,0";
			//var data:String = "M300,200 h-150 a150,150 0 1,0 150,-150 z";
			//var data:String = "M100,200 q50,100 100,0 50,100 100,0 50,100 100,0";
			//var data:String = "M100,200 q50,50 50,0 t60,0 70,0 80,0 90,0 100,0 z";
			//var data:String = "M200,350 l 50,-25 a25,25 -30 0,1 50,-25 l 50,-25 l50,-25";
			//var data:String = "M200,350 l 50,-25 a25,50 -30 0,1 50,-25 l 50,-25 l50,-25";
			//var data:String = "M200,350 l 50,-25 a25,50 -30 0,1 50,-25";
			var data:String = 	"M100,450 "+
								"l 50,-25 "+
								"a25,25 -30 0,0 50,-25 " +
								"l 50,-25 "+
								"a25,50 -30 0,1 50,-25" +
								" l 50,-25 "+
								"a25,75 -30 0,0 50,-25" +
								" l 50,-25 "+
								"a25,100 -30 0," +
								"1 50,-25 l 50,-25";
								
			var path:Path = parser.parse(data);
			var commands:GraphicsPath = path.getCurveSegment();
			//putpoints(commands.data);
			
			//trace(ObjectUtil.toString(path));
			graphics.lineStyle(0, 0x00FF00);
			graphics.beginFill(0x123456, .5);
			graphics.drawPath(commands.commands, commands.data);
			graphics.endFill();
			
			
			/*var cmds:Array = data.split(/\D+/);
			//trace(ObjectUtil.toString(cmds));
			
			//var c:CubicCurve = new CubicCurve(cmds[0], cmds[1], cmds[2], cmds[3], cmds[4], cmds[5]);
			var c:CubicCurve = new CubicCurve(100, 200, 100, 100, 250, 100, 250, 200);
			graphics.moveTo(100, 200);
			var quadData:Array = c.quadratics;
			//throw new Error(ObjectUtil.toString(quadData));
			for each (var cc:Array in quadData) {
				//graphics.moveTo(cc[0], cc[1]);
				graphics.curveTo(cc[2], cc[3], cc[4], cc[5]);
			}*/
		}
		
		protected function putpoints(data:Vector.<Number>):void {
			trace("L "+data.length)
			graphics.beginFill(0xFF0000, 0.7);
			var p:Point = new Point();
			for (var i:uint = 0; i < data.length; i += 2) {
				p.x += data[i];
				p.y += data[i+1];
				graphics.drawCircle(p.x, p.y, 2);
				trace(p);
			}
		}
	}
}